/**
 * Global variables and functions
 */
 var ProjectName = (function($, window, undefined){ 
	var privateVar = 1;
	
	function privateMethod1(){

	};
	
	return {		
		publicVar: 1,
		publicObj: {
			var1: 1,
			var2: 2
		},
		publicMethod1: privateMethod1
	};
})(jQuery, window);

/**
 * Website start here
 */
jQuery(document).ready(function($){
	// remove Value on Search button
	jQuery('#search-art-form #btn-search').length && jQuery('#search-art-form #btn-search').val('');
	// common
	jQuery('.lang-block').length && jQuery('.lang-block').smCustomSelect({
		customOption: true,
		optionTemplate: [
			'<img alt="France" src="'+ jQuery('#img_src').val() +'/images/icon-flag-en.jpg">',
			'<img alt="English" src="'+ jQuery('#img_src').val() +'/images/icon-flag-de.jpg">',
			'<img alt="German" src="'+ jQuery('#img_src').val() +'/images/icon-flag-fr.jpg">',
			'<img alt="Japan" src="'+ jQuery('#img_src').val() +'/images/icon-flag-ja.jpg">'
		],
		afterChoosing: function(val){
			// var country = ['en', 'de', 'fr', 'ja'],
				// hrefPath = window.location.href.split('/');
				// hrefPath[3] = country[$(this).index()];
			// var newHref = '';
				// for(var x = 0; x < hrefPath.length; x ++){
					// if(x != hrefPath.length - 1){
						// newHref +=hrefPath[x] + '/';
					// }
					// else{
						// newHref +=hrefPath[x];
					// }
				// };
			window.location.href = val;
		}
	});
	// menu
	jQuery('#nav').length && jQuery('#nav').smMenu();
	// index
	jQuery('.slider-wrapper').length && jQuery('.slider-wrapper').smBannerSlider({
		slider: '#slider',
		controller: '#control-nav'
	});
	jQuery('.block-type-3').smHoverSlider({
		slideContent: '.block-content .related',
		navHover: '.block-content .list-type-1'
	});
	// user
	jQuery('.slideshow-type-2').length && jQuery('.slideshow-type-2').smBannerSlider({
		slider: 'ul.gallery-type-3',
		controller: '.block-control-nav ul'
	});
	// product
	jQuery('.block-type-5 .block-content').length && jQuery('.block-type-5 .block-content').smBannerSlider({
		slider: '.gallery-type-2',
		controller: '#block-control-nav ul'
	});
	// imma
	jQuery('.imma-block').length && jQuery('.imma-block').smHoverChangeClass({
		classChanged: 'light-box-2',
		changeClassInto: 'light-box-1'
	});
	// cont
	jQuery('.block-type-9').length && jQuery('.block-type-9').smMoreDetail({
		detailContent: '.list-morecategory',
		triggerDetailClass: 'more-category'
	});
	// gale
	jQuery('.author-info').length && jQuery('.author-info').smShowDetail({
		detailContent: '.content-author',
		triggerExtendable: '#open-author',
		triggerCollapsible: '#close-autor'
	});
	jQuery('.galary-img').length && jQuery('.galary-img').smShowGallery();
	jQuery('.cboxElement').length && jQuery('.cboxElement').smShowGallery({
		navControl: false,
		defaultsLink: true
	});
	jQuery('.scroll-highlight').length && jQuery('#container').prepend(jQuery('.scroll-highlight'));
	jQuery('.scroll-highlight').length && jQuery('.scroll-highlight').smShortenBlock();
	jQuery('.list-cat').length && jQuery('.list-cat').smMoreDetail({
		detailContent: 'ul',
		triggerDetailClass: 'more-cat',
		setActiveClass: false,
		animation: 'fade'
	});
	jQuery('.scroll-highlight').length && $(window).bind('scroll', function(){
		if($(window).scrollTop() < (jQuery('.block-type-9').offset().top - 50 + jQuery('.block-type-9').height())){
			jQuery('.scroll-highlight').hide();
		}
		else{
			jQuery('.scroll-highlight').show();
		}
	});
	// gene
	jQuery('.toolbar-outer').length && jQuery('.toolbar-outer').smBlinkHover({
		hoverPoint: '.link',
		blinkContent: '.toolbar'
	});
	//form
	if(jQuery('.webform-client-form').length){
		var checkbox = jQuery('.webform-client-form').find(':checkbox');
		var spanWrapper = $('<span></span>').prependTo(checkbox.parent());
		checkbox.appendTo(spanWrapper);
	}
	jQuery(':radio').length && jQuery(':radio').smCustomRadio({
		checkedClass: 'checked'
	});
	jQuery(':checkbox').length && jQuery(':checkbox').smCustomCheckbox({
		checkedClass: 'checked'
	});
	// jQuery('.form-type-1').length && jQuery('.form-type-1').smValidation({
		// rules: [
			// {
				// name: 'submitted[name]',
				// init: L10N.init.name
			// },
			// {
				// name: 'submitted[email]',
				// valid: 'required|email',
				// init: L10N.init.email,
				// message: L10N.required.email + '|' + L10N.valid.email
			// },
			// {
				// name: 'submitted[message]',
				// init: L10N.init.message
			// }
		// ]
	// });
	jQuery('#search-art-form').length && jQuery('#search-art-form').smAutoValidation({
		rules: [
			{
				type: 'text',
				valid: 'required',
				init: L10N.init.search,
				message: L10N.required.search
			}
		]
	});
	var validateFormat = null;
	if(jQuery('.webform-client-form').find('.isEmail').length){
		validateFormat = [
			{
				type: 'text',
				valid: 'required|email',
				message: L10N.required.email + '|' + L10N.valid.email
			},
			{
				element: 'select',
				valid: 'required',
				reposition: true,
				message: L10N.required.country
			},
			{
				type: 'email',
				init: L10N.init.email
				// valid: 'required|email',
				// message: L10N.required.email + '|' + L10N.valid.email
			},
			{
				element: 'textarea'
			}
		];
	}
	else{
		validateFormat = [
			{
				type: 'text'
			},
			{
				element: 'select',
				valid: 'required',
				reposition: true,
				message: L10N.required.country
			},
			{
				type: 'email',
				valid: 'required|email',
				init: L10N.init.email,
				message: L10N.required.email + '|' + L10N.valid.email
			},
			{
				element: 'textarea'
			}
		];
	}
	jQuery('.webform-client-form').length && jQuery('.webform-client-form').smAutoValidation({
		rules: validateFormat
	});
	// jQuery('.webform-client-form').length && jQuery('.webform-client-form').smValidation({
		// rules: [
			// name: 'submitted[country]',
			// valid: 'required',
			// message: L10N.required.country
		// ]
	// });
	// jQuery('.form-type-1').length && jQuery('.form-type-1').find('select').length && jQuery('.form-type-1').find('select').parent().smCustomSelect({
		// display: 'span.select-custom span',
		
		// triggerDisplay: true,
		// triggerBtn: 'span.select-custom a.click-btn',
		
		// customScroll: true
	// });
	jQuery('.webform-client-form').length && jQuery('.webform-client-form').find('select').length && jQuery('.webform-client-form').find('select').parent().smCustomSelect({
		display: 'span.select-custom span',
		
		triggerDisplay: true,
		triggerBtn: 'span.select-custom a.click-btn',
		
		customScroll: true
	});
	// jQuery('.layer-type-1').length && jQuery('.layer-type-1').smCustomScroll({
		// contentArea : 'div.scroll-block',
		// wrapperContent : 'ul',
		// scrollBar : '.sm-scroll .sm-scroll-dx',
		// scrollBarBtn : 'a'
	// });
	// production
	jQuery('.des-content').length && jQuery('.des-content').smAutoCreateCollapse();
	jQuery('.accordion').length && jQuery('.accordion').smShowAvailableFilm();
	jQuery('.list-category').length && jQuery('.list-category').smScrollAtLink();
	jQuery('.list-morecategory').length && jQuery('.list-morecategory').smScrollAtLink({
		item: 'h3'
	});
	jQuery('.sub-nav-lev3').length && jQuery('.sub-nav-lev3').smScrollAtLink({
		item: 'li'
	});
	jQuery('.list-cat').length && jQuery('.list-cat').smScrollAtLink({
		item: 'li'
	});
});